/**
 * 
 */
package com.waylau.spring.boot.blog.service;

import com.waylau.spring.boot.blog.domain.Forget;
import com.waylau.spring.boot.blog.domain.HotSearch;
import com.waylau.spring.boot.blog.repository.ForgetRepository;
import com.waylau.spring.boot.blog.repository.HotSearchRepository;
import com.waylau.spring.boot.blog.util.Similarity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;

/**
 * Authority 服务.
 * 
 * @since 1.0.0 2017年3月30日
 * @author <a href="https://waylau.com">Way Lau</a>
 */
@Service
public class ForgetServiceImpl implements ForgetService {

	@Autowired
	private ForgetRepository forgetRepository;

	@Override
	public void insert(String pkId,String username) {

		Forget forget = new Forget();
		forget.setId(pkId);
		forget.setCode(username);
		forget.setTime(new Date(System.currentTimeMillis()));

		forgetRepository.save(forget);
		return;
	}

	@Override
	public List<HotSearch> delete() {
		return null;
	}

	@Override
	public Forget findById(String id) {
		return forgetRepository.findOne(id);
	}

	@Override
	public List<Forget> findByCode(String code) {
		return forgetRepository.findByCode(code);
	}

	@Override
	public void updateStatus(String code, Integer status) {
		List<Forget> list = forgetRepository.findByCode(code);
		list.forEach(a->{
			a.setStatus(status);
			forgetRepository.save(a);
		});
	}
}
